let array = {
    clear: function(list) {
        for (let i = list.length - 1; i >= 0; i --) {
            list.splice(i, 1);
        }
        return this;
    },
    addAt: function(list, element, index) {
        list.splice(index, 0, element);
        return this;
    },
    add: function(list, element) {
        list.splice(list.length, 0, element);
        return this;
    },
    addAll: function(list, elementList) {
        for (let i = 0; i < elementList.length; i ++) {
            list.splice(list.length, 0, elementList[i]);
        }
        return this;
    },
    removeAt: function(list, index) {
        return list.splice(index, 1);
    },
    replace: function(list, element, index) {
        list.splice(index, 1, element);
        return this;
    },
    move: function(list, from, to) {
        let success = false;
        if (from >= 0 && from < list.length && to >= 0 && to < list.length && from != to) {
            let node = list[from];
            this.removeAt(list, from);
            this.addAt(list, node, to);
            success = true;
        }
        return success;
    }
};

export default array;